package cn.uce.cc.rest.control;

import cn.uce.base.vo.ArbComplaintsDetVo;
import cn.uce.base.vo.RepeatWorkBillVo;
import cn.uce.base.vo.WaybillInfoChangVo;
import cn.uce.cc.api.service.biz.ICcosWaybillBiz;
import cn.uce.cc.srv.utils.ScreenBusiAbnPubApiConver;
import cn.uce.cc.srv.utils.ScreenBusiArbPubApiConver;
import cn.uce.cc.srv.utils.ScreenBusiWBPubApiConVer;
import cn.uce.common.constants.Constant;
import cn.uce.web.common.base.BaseController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value = "ccos/waybill")
public class CcosWayInfController extends BaseController {

    private Logger log = LoggerFactory.getLogger(CcosWayInfController.class);

    @Resource
    private ICcosWaybillBiz ccosWaybillBiz;

    @RequestMapping(value = "/problemInfo")
    @ResponseBody
    public Map<String, Object> problemInfo(String waybill) {
        List list = null;
        try {
            String apiStr1 = "";
            //TODO
//                    ccosWaybillBiz.getWayBillProblem(waybill);
            String apiStr2 = ccosWaybillBiz.getWayBillProblems(waybill);
            list = ScreenBusiAbnPubApiConver.converterPro(apiStr1, apiStr2);
        } catch (Exception e) {
            returnError("新增客户失败");
        }
        return returnSuccess(list);
    }

    @RequestMapping(value="/problemreportinfo")
    @ResponseBody
    public Map<String, Object> problemreportinfo(String problemNum) {
        try {
            String proStr1 = ccosWaybillBiz.getWayBillProblemDetail(problemNum);
            String proStr2 = "";
            //TODO
//                    ccosWaybillBiz.getWayBillProblemDetails(problemNum);
            Map map = ScreenBusiAbnPubApiConver.converterProDetil(proStr1, proStr2);
            return returnSuccess(map);
        } catch (Exception e) {
            log.error("CcCustmerController,addCcCustomer,Exception", e);
            returnError("新增客户失败");
        }
        return returnSuccess();
    }



     /**
      * 此接口为运单,物流轨迹,代收货款,等信息
       * @Author liupan
       * @Description
       * @Date  2020-06-29 13:45
      * 查询运单信息
       */
    @RequestMapping(value = "/wayBillInfo", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> wayBillInfo(@RequestParam String wayNum)   {
        try {
            return returnSuccess(ccosWaybillBiz.wayBillInfo(wayNum));
        } catch (Exception e) {
            logger.error(wayNum + "通运单号查询运单基础信息出现异常：" + e);
        }
        return returnError("通运单号查询运单基础信息出现异常");
    }


    /**
     * 根据运单号查询详情
     * @return
     */
    @PostMapping("/getWayBillInfoDetail")
    @ResponseBody
    public Map<String, Object> getWayBillInfoDetail(@RequestParam String wayNum){
        try {
            return returnSuccess(ccosWaybillBiz.getWayBillInfoDetail(wayNum));
        } catch (Exception e) {
            logger.error(wayNum + "getWayBillInfoDetail：" + e);
        }
        return returnError("通运单号查询运单基础信息出现异常");
    }



    @RequestMapping(value = "/queryarbinfo", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> getArbInfo(@RequestParam String wayNum) {
        Map<String, Object> map = new HashMap<>();
        try {
            String apiStr = "";
            //TODO
//                    ccosWaybillBiz.getArbitrationInfoByWBNo(wayNum);
            map = ScreenBusiArbPubApiConver.converterArb_List(apiStr);
            return returnSuccess(map);
        } catch (Exception e) {
            logger.error(wayNum + "通过运单号查询仲裁出现异常：" + e);
        }
        return returnSuccess();
    }

    @RequestMapping(value = "/complaint", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> getComplaint(@RequestParam String complaintNum) {
        ArbComplaintsDetVo arbComplaintsVo = null;
        try {
            String complaint = "";
            //TODO
//                    ccosWaybillBiz.getComplaint(complaintNum);
            arbComplaintsVo = ScreenBusiArbPubApiConver.converterArb_Detail(complaint);
            return returnSuccess(arbComplaintsVo);
        } catch (Exception e) {
            logger.error(complaintNum + "通过运单号查询仲裁详情出现异常：" + e);
        }
        return returnError("通过运单号查询仲裁详情出现异常");
    }


    /**
     * 工单重复投诉
     * @param repeatWorkBillVo
     * @return
     */
    @RequestMapping(value = "/repeatWorkBill", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> repeatWorkBill(RepeatWorkBillVo repeatWorkBillVo) {
        try {
            ccosWaybillBiz.repeatWorkBill(repeatWorkBillVo);
            return returnSuccess("重复投诉成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return returnError("请求异常");
    }

    @RequestMapping(value = "/receiptmoney", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> getReceiptMoney(String wayNum) throws Exception {
        try {
            return returnSuccess(ccosWaybillBiz.getReceiptMoney(wayNum));
        } catch (Exception e) {
            logger.error(wayNum + "通过运单号查询代收货款出现异常：" + e);
        }
        return returnError("通过运单号查询代收货款出现异常");
    }

    @RequestMapping(value = "/waybillproblem", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> getwayBillProblem(@RequestParam String wayNum) throws Exception {
        List<WaybillInfoChangVo> waybillInfoChangVo_list = new ArrayList();
        try {
            String apiStr = ccosWaybillBiz.getWayBillChangeInfo(wayNum);
            waybillInfoChangVo_list = ScreenBusiWBPubApiConVer.converterQueryWBChange(apiStr);
            return returnSuccess(waybillInfoChangVo_list);
        } catch (Exception e) {
            logger.error(wayNum + "通过运单号查询运单信息变更出现异常：" + e);
        }
        return returnError("通过运单号查询运单信息变更出现异常");
    }
}
